package com.jetlion.menu;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    //重写菜单，加载自定义菜单
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }

    //重写点击事件
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_create:
                Toast.makeText(MainActivity.this, "点击了 创建", Toast.LENGTH_LONG).show();
                break;
            case R.id.menu_open:
                Toast.makeText(MainActivity.this, "点击了 打开", Toast.LENGTH_LONG).show();
                break;
            case R.id.menu_aboutus:
                Toast.makeText(MainActivity.this, "点击了 关于我们", Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }
        return true;
    }
}